package com.ruoyi.business.util;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class PhoneUtil {
    public static String formatPhone(String phoneNumber) {
        try{
            //字符过滤
            phoneNumber = phoneNumber==null?"":phoneNumber;
            phoneNumber = phoneNumber.replaceAll(" ","");
            phoneNumber = phoneNumber.replaceAll("[^A-Za-z0-9 ]", "");
            phoneNumber = phoneNumber.startsWith("0") ? "234" + phoneNumber.substring(1) : (phoneNumber.startsWith("2340") ? phoneNumber.replace("2340", "234") : phoneNumber);
            return phoneNumber;
        }catch (Exception e){
            log.error("手机号格式清洗异常:",e);
            return "";
        }
    }
}
